import { getRequest, getExportFileRequest, download, postBodyRequest, patchBodyRequest, postFormRequest } from '../../utils/http'
import axios from 'axios'

// 获取所有设备信息、包括分页、模糊查询、条件检索
export const getDevice = function (param) {
  return getRequest('/public/device', param)
}

// 根据ID获取设备信息
export const searchDevice = function (param) {
  return getRequest('/public/device/', param)
}

// 根据认证Id调取编辑数据
export const getAuthId = (data) => {
  return axios({
    method: 'get',
    url: '/public/device/authId/' + data
  })
}

// 导出设备信息到excel
export const exportFile = function (param) {
  return getExportFileRequest('/public/excel/export', param)
}

// 下载模板
export const downloadFile = function () {
  return download('/public/excel/download')
}

// 修改设备状态
export const changeDevice = function (param) {
  return patchBodyRequest('/public/device', param)
}

// 删除设备信息
export const deleteDevice = (data) => {
  return axios({
    method: 'delete',
    url: '/public/device/' + data
  })
}

// 新增设备信息
export const addDevice = function (param) {
  return postBodyRequest('/public/device', param)
}

// 获取组织列表信息
export const getOrganization = function (param) {
  return getRequest('/organization', param)
}

// 获取绑定人员信息
export const getPerson = function (param) {
  return getRequest('/user/employees', param)
}

// 获取巡逻区域
export const getArea = function (param) {
  return getRequest('/cmd/area', param)
}

// 解除设备绑定
export const unBind = function (param) {
  // eslint-disable-next-line no-unused-vars
  let url
  if (Object.keys(param).length) {
    for (const key in param) {
      url = `/${param[key]}`
    }
  }
  return axios({
    method: 'patch',
    url: '/public/unbind/',
    param
  })
}

// 导入设备信息
export const importDevice = function (param) {
  return postFormRequest('/public/excel/import', param)
}
